﻿@page "/Upload"
@using ICarlifeService;
@using Models;
@using static Commonality.Examineandapprove;
@using static Commonality.Client;
@inject ICarLeaseProjectService CarLeaseProjectService;
@inject NavigationManager navigationManager;
@inject DialogService DialogService;


<div class="col-12">
    <Table TItem="CarLeaseProject" Items="@Items" IsBordered="true" IsStriped="true" ShowToolbar="false" ShowAddButton="false" ShowEditButton="false" ShowExtendButtons="true" OnQueryAsync="@OnQueryAsync" ShowExtendEditButton="false" ShowExtendDeleteButton="false">
        <TableColumns>
            <TableColumn Text="项目ID" @bind-Field="@context.Id" Width="180" />
            <TableColumn Text="契约编号" @bind-Field="@context.ContractNo" />
            <TableColumn Text="客户名称" @bind-Field="@context.Name" />
            <TableColumn Text="客户类型" @bind-Field="@context.Customer" />
            <TableColumn Text="先付比例" @bind-Field="@context.Localresidence" />
            <TableColumn Text="贷款金额" @bind-Field="@context.Localdriving" />
            <TableColumn Text="业务经办" @bind-Field="@context.IDCard" />
            <TableColumn Text="项目归属" @bind-Field="@context.Ownership" />
            <TableColumn Text="业务状态" @bind-Field="@context.Checked" />
            <TableColumn Text="立项日期" @bind-Field="@context.ProjectApprovalDate" />
            
        </TableColumns>
        <BeforeRowButtonTemplate >
            @if (context.Checked.Equals(Examine.Projecttobeinitiated))
            {
                <TableCellButton Color="Color.Primary" Icon="fa-solid fa-pen" Text="提交立项" OnClick="@(() => OnRowButtonClick(context, "提交立项"))" />
                <TableCellButton Color="Color.Success" Icon="fa-solid fa-pen" Text="编辑" OnClick="@(() => OnRowButtonClick(context, "编辑"))" />
                <TableCellButton Color="Color.Warning" Icon="fa-solid fa-pen" Text="删除" OnClick="@(() => OnRowButtonClick(context, "删除"))" />
            }
            @if (context.Checked.Equals(Examine.Project_approval))
            {
                <TableCellButton Color="Color.Primary" Icon="fa-solid fa-pen" Text="确认立项" OnClick="@(() => OnRowButtonClick(context, "确认立项"))" />
                <TableCellButton Color="Color.Warning" Icon="fa-solid fa-pen" Text="作废" OnClick="@(() => OnRowButtonClick(context, "作废"))" />
            }
            @if (context.Checked.Equals(Examine.Project_approval_Confirm))
            {
                <TableCellButton Color="Color.Primary" Icon="fa-solid fa-pen" Text="恢复" OnClick="@(() => OnRowButtonClick(context, "恢复"))" />
                <TableCellButton Color="Color.Warning" Icon="fa-solid fa-pen" Text="删除" OnClick="@(() => OnRowButtonClick(context, "删除"))" />
            }
            @if (context.Checked.Equals(Examine.Onlease))
            {
                <TableCellButton Color="Color.Primary" Icon="fa-solid fa-pen" Text="起租" OnClick="@(() => OnRowButtonClick(context, "起租"))" />
                <TableCellButton Color="Color.Warning" Icon="fa-solid fa-pen" Text="作废" OnClick="@(() => OnRowButtonClick(context, "作废"))" />
            }
            <TableCellButton Color="Color.Danger" Icon="fa-solid fa-pen" Text="项目指派" OnClick="@(() => OnRowButtonClick(context, "项目指派"))" />
            <TableCellPopconfirmButton Color="Color.Info" Icon="fa-solid fa-pen" Text="日志" OnConfirm="@(() => OnRowButtonClick(context, "日志"))" />
        </BeforeRowButtonTemplate>
    </Table>
</div>

@code {
    private List<CarLeaseProject> Items = new();
    protected override async Task OnInitializedAsync()
    {

        Items = await  CarLeaseProjectService.Show();

        await base.OnInitializedAsync();
    }
    private Task<QueryData<CarLeaseProject>> OnQueryAsync(QueryPageOptions options)
    {
        // Set the total number of records
        var total = Items.Count;
        // memory paging
        var items = Items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();
        return Task.FromResult(new QueryData<CarLeaseProject>() { Items = items, TotalCount = total, IsSorted = true, IsFiltered = true, IsSearch = true });
    }
    private async Task OnRowButtonClick(CarLeaseProject item, string text)
    {
        @if (text == "提交立项")
        {
            item.Checked = Examine.Project_approval;
            await  CarLeaseProjectService.Updateps(item);
        }
        @if (text == "确认立项")
        {
            navigationManager.NavigateTo($"/AuditSet/{item.Id}");
           }
        @if (text == "项目指派")
        {
            navigationManager.NavigateTo($"/Projectassignment/{item.Id}");
        }
        
    }
}

